import React, {Component} from 'react';
import {Text } from 'react-native';
import {Flex} from 'antd-mobile-rn';
export default class CText extends Component {

    //构造函数
    constructor(props) {
        super(props);
        this.state = {
            titleHeight:props.initHeight ? props.initHeight : 0,
            numberOfLines:props.numberOfLines ? props.numberOfLines : 3,
        };
    }

    componentDidMount() {
    }

    //组件卸载
    componentWillUnmount() {

    }

    componentWillReceiveProps(nextProps) {
    }

    render() {
        return (
            <Flex wrap="wrap" style={[{justifyContent:"center",height:this.state.titleHeight+6,marginTop:3,marginBottom:3},this.props.style?this.props.style:{}]}>
                    <Text style={[{color:"black"},this.props.textstyle?this.props.textstyle:{}]} numberOfLines={this.state.numberOfLines} onLayout={(event)=>{ 
                        let height = event.nativeEvent.layout.height;
                        if(this.titleHeight<height)
                            console.log("标题大小"+this.titleHeight);
                            this.setState({
                                titleHeight:height
                            });
                        }}>
                        {this.props.title}
                    </Text>
            </Flex>
        );
    }
}